package com.mego.design.mode01Singleton.LazySingleton;

public class Premier {
    private static volatile Premier instance = null;    //保证instance在所有线程中同步
    //private避免类在外部被实例化
    private Premier() {
        System.out.println("产生一个首相！");
    }
    public static synchronized Premier getInstance() {
        //在getInstance方法上加同步
        if (instance == null) {
            instance = new Premier();
        } else {
            System.out.println("已经有一个首相，不能产生新首相！");
        }
        return instance;
    }
    public void getName() {
        System.out.println("我是英国首相：李某某");
    }
}
